<?php
namespace Home\Controller;
use Think\Controller;
class DataOutController extends Controller {

	public function index()
    {
    	echo "这里是数据导出";
    }

    //导出2015年所有企业补助的数据
    public function out1129()
    {
    	
		$db=D("ComBzxx");
		$com_db=D("CzjCom");

		$xm_arr=$db->get_xm();

		foreach($xm_arr as $xm_id=>$xm_name)
		{
			$where="(ssnd = 2015) AND (nowtype = 4) and sszxid=".$xm_id;
			$order="sszxid asc,sscomid asc";

			//读取补助记录并展开
			$bz_rows = $db->getAllRows($where);
			if(empty($bz_rows)) continue;

			$table_tr="补助项目名称,企业名称,";

			$bzxm_mxs=$db->get_xmms($xm_id,2015);
			foreach($bzxm_mxs as $bzxm_mx)
				$table_tr.=$bzxm_mx."_税收金额,".$bzxm_mx."_补助金额,";

			$table_tr.="\r\n";



			foreach($bz_rows as $bz_row)
			{
				//print_r($bz_row);
				//补助明细
				$bzmx_rows=$db->getMxRows($bz_row['bzxxid']);
				if(empty($bzmx_rows)) continue;
				
				
				//项目名称
				$table_tr.=$xm_name.",";

				//企业名称
				$com_info=$com_db->findById($bz_row['sscomid']);
				$table_tr.=$com_info['com_name'].",";

				
				foreach($bzxm_mxs as $bzxm_id=>$bzxm_mx)
				{
					foreach($bzmx_rows as $bzmx_row)
					{

						if($bzmx_row['ssxmid']==$bzxm_id)
						{
							$table_tr.=$bzmx_row['sjssje'].",".$bzmx_row['sjz'].",";
						}
					}
				}



				$table_tr.="\r\n";
			}
			$table_tr.="\r\n";
			$table_tr.="\r\n";
			echo $table_tr;
		}



		//die();
    }
}